package com.beidouapp.translator;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.beidouapp.cache.CacheConstants;
import com.beidouapp.cache.JbossCacheProvider;
import com.beidouapp.cache.impl.CacheTranslatorImpl;
import com.beidouapp.dao.RoleGroupDao;
import com.beidouapp.domain.pojo.RoleGroup;
import com.beidouapp.translate.Translator;

@Component
public class DistrictTranslator extends CacheTranslatorImpl implements Translator{
	/**
	 * 日志记录器.
	 */
	private static final Logger logger = LoggerFactory
			.getLogger(RoleGroupTranslator.class);
	
	private JbossCacheProvider jbossCacheProvider;
	
	@Autowired
	public void setJbossCacheProvider(JbossCacheProvider jbossCacheProvider) {
		this.jbossCacheProvider = jbossCacheProvider;
		super.setJbossCacheProvider(jbossCacheProvider);
	}

	@Override
	public String getTranslatorName() {
		return "districtTranslator";
	}

	@Override
	public String translate(String fullQuilifiedName, String sourceFieldValue) {
		if (StringUtils.isBlank(sourceFieldValue)) {
			return "";
		}
		try {
			String value = (String) jbossCacheProvider
					.getMapCacheValuep(CacheConstants.ADDRESS_NAMESPACE,
							"tcode", sourceFieldValue);
			if (value == null)
				value = "";
			return value;
		} catch (Exception e) {
			logger.error("翻译失败！");
		}
		return "";
	}
	
	@Override
    public boolean isExistItem (String fullQualifiedName, String sourceFieldValue)
    {
        return false;
    }
	
	@Override
	public boolean addItem(String fullQualifiedName, String sourceFieldValue,
			String targetFieldValue) {
		return true;
	}
}
